package com.huarun.common;

import com.huarun.common.util.Constant;
import com.huarun.common.util.ResultCodeValue;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 
 * @author hqy
 * @创建时间   2018-10-17 13:57
 * @Description 消息响应
 * @param <T>
 */
@ApiModel(value = "ResponseMessage", description = "响应对象封装类，当code为0时获取data中对应的数据")
public class ResponseMessage<T> {
	@ApiModelProperty(value = "返回码", required = true)
	private int code=200;
	@ApiModelProperty(value = "是否刷新")
	private boolean update=false;
	@ApiModelProperty(value = "消息")
	private String message;
	@ApiModelProperty(value = "返回数据")
	private T data;
	@ApiModelProperty(value = "时间戳", required = true)
	private long ts;

	public static ResponseMessage succMessage(String message, Object data, Long timestamp) {
		ResponseMessage responseMessage = new ResponseMessage();
		responseMessage.code = ResultCodeValue.R_SUCCESS;
		responseMessage.message = message;
		responseMessage.data = data;
		if (timestamp == null) {
			responseMessage.ts = System.currentTimeMillis();
		} else {
			responseMessage.ts = timestamp;
		}
		return responseMessage;

	}

	public static ResponseMessage failureMessage(int code, String message, Long timestamp) {
		ResponseMessage responseMessage = new ResponseMessage();
		responseMessage.code = code;
		responseMessage.message = message;
		if (timestamp == null) {
			responseMessage.ts = System.currentTimeMillis();
		} else {
			responseMessage.ts = timestamp;
		}
		return responseMessage;

	}

	public ResponseMessage() {
	}

	public ResponseMessage(int code, String message, long ts) {
		this.code = code;
		this.message = message;
		this.ts = ts;
	}

	public void setCodeAndMsg(int code, String message) {
		this.code = code;
		this.message = message;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public boolean isUpdate() {
		return update;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public long getTs() {
		return ts;
	}

	public void setTs(long ts) {
		this.ts = ts;
	}
}
